<?php
//处理用户投诉
class ComplaintsAction extends PublicAction{
	public function index(){
		
	}
	//增加用户投诉
	public function addComplaints(){
		if ($this->isLogin() && $_POST["user_id"]==$this->isLogin() ){
			$complaints_list=D("ComplaintsList");
			$data=array(
						"title"=>"用户增加了投诉",
						"content"=>mysql_escape_string($_POST["content"]),
						"user_id"=>intval($_POST["user_id"]),
						"add_time"=>time(),
						"order_id"=>mysql_escape_string($_POST["order_id"]),
						"parent_id"=>intval($_POST["parent_id"]),
						"type"=>intval($_POST["type"]),
						"complaints_status"=>intval($_POST["complaints_status"]),
						"ip"=>getIP()
					);
			if ($complaints_list->add($data)){
				if (!empty($_GET["url"])){
					URLS(urldecode($_GET["url"]));
					exit(0);
				}
				JSON(1,"数据已经成功保存",1);
			}else{
				
				Log::write("用户在新增投诉时，发生了致命错误：".$complaints_lsit->getLastSql());
				JSON(0,"数据保存失败".$complaints_list->getLastSql(),0);
			}
		}else{
			JSON(0,"登录超时",0);
		}
	}
	//用户删除投诉
	public function delComplaints(){
		if ($this->isLogin()){
			$complaints_list=D("ComplaintsList");
			
			$where=array(
					"complaints_id"=>intval($_GET["id"]),
					"user_id"=>intval($this->isLogin())
					);
			$rows=$complaints_list->where($where)->find();
			if ($rows["user_id"]!=$this->isLogin()) JSON(0,"权限出错",0);
			if ($complaints_list->where($where)->delete()){
				if (!empty($_GET["url"])){
					URLS(urldecode($_GET["url"]));
					exit(0);
				}
				JSON(1,"数据删除成功",1);
			}else{
				Log::write("用户在删除投诉时，发生了致命错误：".$complaints_list->getLastSql());
				JSON(0,"数据删除失败".$complaints_list->getLastSql(),0);
			}
			
		}else{
			JSON(0,"登录超时",0);
		}
		
	}
}